(function(){function r(e,n,t){function o(i,f){if(!n[i]){if(!e[i]){var c="function"==typeof require&&require;if(!f&&c)return c(i,!0);if(u)return u(i,!0);var a=new Error("Cannot find module '"+i+"'");throw a.code="MODULE_NOT_FOUND",a}var p=n[i]={exports:{}};e[i][0].call(p.exports,function(r){var n=e[i][1][r];return o(n||r)},p,p.exports,r,e,n,t)}return n[i].exports}for(var u="function"==typeof require&&require,i=0;i<t.length;i++)o(t[i]);return o}return r})()({1:[function(require,module,exports){
"use strict";

loader.define({
  depend: ['pages/config/config'],
  loaded: function loaded(config, require, exports, module, global) {
    this.pageview = {
      init: function init(e) {
        var url;
        var getParams = bui.getPageParams();
        getParams.done(function (result) {
          url = result['url'];
          console.log(url);
        });
        var pc = new PhotoClip('#clipArea', {
          size: [260, 260],
          outputSize: 640,
          //adaptive: ['60%', '80%'],
          file: '#file',
          //img:'images/home/user_image.jpg',
          ok: '#clipBtn',
          //img: 'img/mm.jpg',
          loadStart: function loadStart() {
            console.log('开始读取照片');
          },
          loadComplete: function loadComplete() {
            console.log('照片读取完成');
          },
          done: function done(dataURL) {
            //console.log("1:    "+dataURL);
            // var file = dataURLtoFile(dataURL, Date.now()+'.png');
            // var form = new FormData();
            // form.append("avatar",file,"liger");
            // bui.ajax({
            //     url: config.apiurl + "api/v1.0/changeAvatar",
            //     method: 'POST',
            //     cache: false, //上传文件不需要缓存
            //     data: form,
            //     processData: false, // 告诉jQuery不要去处理发送的数据
            //     contentType: false, // 告诉jQuery不要去设置Content-Type请求头
            //     success: function (data) {
            //         console.log(data);s
            //     }
            // })
            var uiLoading = bui.loading();
            uiLoading.show();
            var data2 = {
              base64: dataURL
            };
            data2 = JSON.stringify(data2);
            console.log(data2);
            bui.ajax({
              url: config.apiurl + "api/v1.0/changeAvatar2",
              data: data2,
              method: "post",
              headers: {
                'Content-Type': 'application/json'
              }
            }).then(function (res) {
              //静态设置头像
              var $uploadBtn1 = $("#mine_my_big_part1");
              $uploadBtn1.html(templatePhoto(dataURL));
              uiLoading.hide();
              bui.hint({
                content: "<i class='icon-check'></i><br />修改成功",
                position: "center",
                effect: "fadeInDown"
              });
              bui.back();
              console.log(res);
            }, function (res, status) {
              alert("修改失败，请检查网络！");
              bui.back();
            }); // //静态设置头像
            // var $uploadBtn1 = $("#mine_my_big_part1");
            // $uploadBtn1.html(templatePhoto(dataURL));
            // bui.hint({ content: "<i class='icon-check'></i><br />修改成功", position: "center", effect: "fadeInDown" });
            // bui.back();
          },
          fail: function fail(msg) {
            bui.hint(msg);
          }
        }).load(url); //pc.destroy();

        function dataURLtoFile(dataurl, filename) {
          var arr = dataurl.split(','),
              mime = arr[0].match(/:(.*?);/)[1],
              bstr = atob(arr[1]),
              n = bstr.length,
              u8arr = new Uint8Array(n);

          while (n--) {
            u8arr[n] = bstr.charCodeAt(n);
          }

          return new File([u8arr], filename, {
            type: mime
          });
        } // 加载的图片必须要与本程序同源，否则无法截图
        //pc.load('images/home/user_image.jpg');


        function templatePhoto(url) {
          return "<img src=\"".concat(url, "\" height=\"100%\" />");
        }
      }
    };

    this.pageview.refresh = function () {
      location.reload();
    };

    this.pageview.init();
    return this.pageview;
  }
});
},{}]},{},[1]);
